<?php

$body = imageCreateFromPNG("./images/body.png");

$hair = imageCreateFromPNG("./images/hair.png");
$armor = imageCreateFromPNG("./images/armor.png");

//imagealphablending($body, False);
imagesavealpha($body, True);
//imagealphablending($hair, True);
//imagealphablending($armor, True);

if(isset($_REQUEST['h']))
{
	$ha = explode(',', $_REQUEST['h']);
	if(count($ha) == 3)
	{
		list($hr, $hg, $hb) = $ha;
	}
}

if(!isset($hr))
{
	$hr = rand(0, 200);
	$hg = rand(0, 200);
	$hb = rand(0, 200);
}

if(isset($_REQUEST['a']))
{
	$aa = explode(',', $_REQUEST['a']);
	if(count($aa) == 3)
	{
		list($ar, $ag, $ab) = $aa;
	}
}

if(!isset($ar))
{
	$ar = rand(0, 200);
	$ag = rand(0, 200);
	$ab = rand(0, 200);
}

imagefilter($hair, IMG_FILTER_COLORIZE, $hr, $hg, $hb);
imagefilter($armor, IMG_FILTER_COLORIZE, $ar, $ag, $ab);

imageCopyResampled($body, $hair, 0, 0, 0, 0, imagesx($hair), imagesy($hair), imagesx($body), imagesy($body));
imageCopyResampled($body, $armor, 0, 0, 0, 0, imagesx($armor), imagesy($armor), imagesx($body), imagesy($body));

header('Content-type: image/png');
imagePNG($body);

?>
